class ImportPinyinData < ActiveRecord::Migration
  def self.up
    create_table :pinyin, :options => 'ENGINE=InnoDB DEFAULT CHARSET=UTF8' do |t|
      t.column :initial, :string
      t.column :pinyin, :string
      t.column :glyph, :string
    end
    
    f = File.open(File.join(File.dirname(__FILE__), "/pinyin.txt" ))
    f.each do |line|
      if line =~ /^(.) ([a-z]*)/u 
        pinyin = $2
        glyph = $1
        Pinyin.create({:initial => pinyin[0,1], :pinyin => pinyin, :glyph => glyph})
      end
    end
    
  end
  
  def self.down
    drop_table :pinyin
  end
end

class Pinyin < ActiveRecord::Base
  set_table_name "pinyin"
end
